import Taro from "@tarojs/taro"
import {isLogin, qsStringify} from "./common"

export const routerBack = () => {
	Taro.navigateBack()
}

/**前往设备绑定确认页面 */
export const toConfirmBindDev = (devGId: string) => {
	Taro.navigateTo({
		url: `/pages/confirmBindDev/index?devGId=${devGId}`
	})
}

//? 数据分析页 以及其二级页面 starts-----------------------------------

/**前往登录页 */
export const toLogin = () => {
	Taro.navigateTo({
		url: `/pages/login/index`
	})
}

/**前往首页 数据分析页 */
export const toHome = () => {
	Taro.switchTab({
		url: `/pages/home/index`
	})
}

/**前往设备绑定成功页 */
export const toBindDevSuccess = () => {
	Taro.navigateTo({
		url: "/pages/bindDevSuccess/index"
	})
}
/**前往设备绑定失败页 */
export const toBindDevError = () => {
	Taro.navigateTo({
		url: "/pages/bindDevError/index"
	})
}

/**前往单设备数据查看页 */
export const toEchartsSingleDevParamsAnalyze = (devId: string | number) => {
	Taro.navigateTo({
		url: `/pages-echarts/pages/singleDevParamsAnalyze/index?devId=${devId}`
	})
}

/**前往历史记录页 */
export const toHomeParamsHistory = (devId: string | number, devName: string) => {
	Taro.navigateTo({
		url: `/pages-home/pages/paramsHistory/index?devId=${devId}&devName=${devName}`
	})
}

/**前往设备异常详情页 */
export const toHomeWarningInfo = (devId: string | number) => {
	Taro.navigateTo({
		url: `/pages-home/pages/warningInfo/index?devGId=${devId}`
	})
}

/**前往设备参数异常列表页 */
export const toHomeSingleDevParams = (devId: string | number) => {
	Taro.navigateTo({
		url: `/pages-home/pages/singleDevParams/index?devGId=${devId}`
	})
}

/**前往单参数分析页 */
export const toEchartsSingleParamAnalyze = (devId: string | number) => {
	Taro.navigateTo({
		url: "/pages-echarts/pages/singleParamAnalyze/index?devId=" + devId
	})
}

/**前往报警信息页 */
export const toWarning = (devId: string | number) => {
	Taro.navigateTo({
		url: "/pages-home/pages/warning/index?devId=" + devId
	})
}

/**前往报警信息页 */
export const toAllWarning = () => {
	Taro.navigateTo({
		url: "/pages-home/pages/allWarning/index"
	})
}

/**前往异常信息页 */
export const toAbnormal = (devId: string | number) => {
	Taro.navigateTo({
		url: "/pages-home/pages/abnormal/index?devId=" + devId
	})
}

//! 数据分析页 以及其二级页面 end-----------------------------------

//? 设备设置页 以及其二级页面 starts-----------------------------------

/**前往设备设置入口页 */
export const toSettingAccess = (data: {devId: string | number; isManage: IsManage}) => {
	console.log("设备分享标识", data)

	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/access/index?${str}`
	})
}

/**前往设备日志页 */
export const toSettingDevLog = (devId: string | number, devName: string) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/devLog/index?devId=${devId}&devName=${devName}`
	})
}

/**前往设备产品资料页 */
export const toSettingProductFiles = (devId: string | number, devName: string) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/productFiles/index?devId=${devId}&devName=${devName}`
	})
}

/**前往设备产品资料详情页 */
export const toSettingProductFileInfo = (data: Setting.FileData & {devId: string | number}) => {
	let qsStr = Object.keys(data)
		.map(key => `${key}=${data[key] || ""}`)
		.join("&")
	Taro.navigateTo({
		url: `/pages-setting/pages/productFileInfo/index?${qsStr}`
	})
}

/**前往单设备分享设备列表 自己的设备进入这个页面*/
export const toSingleDevShareList = (data: {
	devId: string | number
	devName: string
	isManage: IsManage
}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/singleDevShareList/index?${str}`
	})
}

/**前往分享设备 */
export const toShareDev = (data: {devId: string | number; devName: string}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/shareDev/index?${str}`
	})
}

/**前往解除分享设备 */
export const toDisShareDev = (data: {
	devId: string | number
	devName: string
	shareUserName: string
	shareTime: string
	userDevId: number
}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/disShareDev/index?${str}`
	})
}

/**前往基本信息页 */
export const toDevBaseInfo = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/devBaseInfo/index?${str}`
	})
}

/**前往基本信息修改页 自己的设备进入这个页面*/
export const toBaseInfoEdit = (data: {devId: string | number}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/baseInfoEdit/index?${str}`
	})
}
/**前往基本信息修改页 被分享的设备进入这个页面*/
export const toBeSharedBaseInfoEdit = (data: {devId: string | number}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/beSharedBaseInfoEdit/index?${str}`
	})
}

/**前往服务信息页 */
export const toServerInfo = (data: {devId: string | number}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/serverInfo/index?${str}`
	})
}

/**前往设备信息页 */
export const toDevInfo = (data: {devId: string | number}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/devInfo/index?${str}`
	})
}

// 前往DPD控制页面
export const toDpdControl = (data: {devGId: string | number}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/dpdControl/index?devGId=${data.devGId}`
	})
}

/* 前往GJ004开关控制页面 */
export const toGJ004Switch = (data: {devGId: string | number; devId: string | number}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/GJ004Switch/index?devGId=${data.devGId}&devId=${data.devId}`
	})
}

/* 前往水站控制页面 */
export const toWaterSupplyStationControl = (data: {
	devGId: string | number
	devId: string | number
}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/waterSupplyStationControl/index?devGId=${data.devGId}&devId=${data.devId}`
	})
}

/* 前往测量控制页面 */
export const toMeasureControl = (data: {devGId: string | number; devId: string | number}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/measureControl/index?devGId=${data.devGId}&devId=${data.devId}`
	})
}

/* 前往雨水控制页面 */
export const toRainControl = (data: {devGId: string | number; devId: string | number}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/rainControl/index?devGId=${data.devGId}&devId=${data.devId}`
	})
}

/* 前往 G1680A 控制页面 */
export const toG1680AControl = (data: {devGId: string | number; devId: string | number}) => {
	Taro.navigateTo({
		url: `/pages-setting/pages/G1680AControl/index?devGId=${data.devGId}&devId=${data.devId}`
	})
}

/**前往报警配置页 */
export const toSetReport = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)

	Taro.navigateTo({
		url: `/pages-setting/pages/setReport/index?${str}`
	})
}
/**前往标准配置页 */
export const toStandardConfig = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)

	Taro.navigateTo({
		url: `/pages-setting/pages/standardConfig/index?${str}`
	})
}

/**前往参数标准设置页 */
export const toParamStandardSetting = (data: {
	devId: string | number
	paramName: string
	devSRId: number
}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/paramStandardSetting/index?${str}`
	})
}

/**前往采集频率设置页 */
export const toCollectRateSetting = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/collectRateSetting/index?${str}`
	})
}

/**前往数据上传开关设置页 */
export const toUploadSwitchSetting = (data: {devId: string | number}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/uploadSwitchSetting/index?${str}`
	})
}

/**前往所有设备的异常信息页 */
export const toAllAbnormal = () => {
	Taro.navigateTo({
		url: "/pages-setting/pages/allAbnormal/index"
	})
}

/**前往附加配置页 */
// toAdditionConfig
export const toAdditionConfig = (data: {
	devId: string | number
	isManage: IsManage
	devGId: string
}) => {
	let str = qsStringify(data)
	console.log(str)
	console.log(data.devGId)

	Taro.navigateTo({
		url: `/pages-setting/pages/additionConfig/index?${str}`
	})
}

/**前往设备控制页 */
export const toDevControll = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/devControlls/index?${str}`
	})
}

/* 前往功能控制2页面 */
export const toDevControll2 = (data: {devId: string | number; isManage: IsManage}) => {
	let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-setting/pages/devControll2/index?${str}`
	})
}

//! 设备设置页 以及其二级页面 end-----------------------------------

//? 个人设置页 以及其二级页面 start-----------------------------------
/**前往个人信息页 */
export const toUserInfo = () => {
	// let str = qsStringify(data)
	if (!isLogin()) return
	Taro.navigateTo({
		url: `/pages-user/pages/userInfo/index`
	})
}

/**前往昵称修改页 */
export const toEditNearName = () => {
	// let str = qsStringify(data)
	Taro.navigateTo({
		url: `/pages-user/pages/editNearName/index`
	})
}

/**前往公司名称修改页 */
export const toEditCompanyName = () => {
	// let str = qsStringify(data)
	if (!isLogin()) return

	Taro.navigateTo({
		url: `/pages-user/pages/editCompanyName/index`
	})
}

/**前往手机号修改页 */
export const toEditUserPhone = () => {
	// let str = qsStringify(data)
	if (!isLogin()) return
	Taro.navigateTo({
		url: `/pages-user/pages/editUserPhone/index`
	})
}

/**前往系统通知页 */
export const toSystemNotification = () => {
	if (!isLogin()) return
	Taro.navigateTo({
		url: `/pages-user/pages/systemNotification/index`
	})
}

/**前往设备监控页 */
export const toVideoSurveillance = () => {
	Taro.navigateTo({
		url: `/pages-user/pages/videoSurveillance/index`
	})
}

/**前往联系我们页 */
export const toAboutUs = () => {
	Taro.navigateTo({
		url: `/pages-user/pages/aboutUs/index`
	})
}

/**前往关于公司页 */
export const toContactUs = () => {
	Taro.navigateTo({
		url: `/pages-user/pages/contactUs/index`
	})
}

/**前往修改监控配置 */
export const toEditVideoSurveillance = ({cameraId}: {cameraId: number}) => {
	Taro.navigateTo({
		url: `/pages-user/pages/editVideoSurveillance/index?cameraId=${cameraId}`
	})
}

/**前往添加监控 */
export const toAddVideoSurveillance = () => {
	Taro.navigateTo({
		url: `/pages-user/pages/addVideoSurveillance/index`
	})
}
//! 个人设置页 以及其二级页面 end-----------------------------------

//? 其他页面 -----------------------------------
/**前往微信扫码授权页 */
export const toWxScanAuth = (data: {address: string}) => {
	if (!isLogin()) return
	Taro.navigateTo({
		url: `/pages-user/pages/wxScanAuth/index?address=${data.address}`
	})
}
